package com.wasu.sdk_ott.provider

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
import com.wasu.constant.TAG

/**
 * <p>------------------------------------------------------
 * <p>Copyright (C) 2020 wasu company, All rights reserved.
 * <p>------------------------------------------------------
 * <p> 本地数据库初始化
 * <p> /data/user/0/com.wasu.launcher/databases/livedata
 *
 * @author Created by zhangmz
 * @date on 2023/9/4
 */
class DatabaseHelper(
    context: Context
): SQLiteOpenHelper(context, "livedata", null, 18) {

    override fun onCreate(db: SQLiteDatabase?) {
        Log.v(TAG, "--DatabaseHelper--onCreate--")
        db?.execSQL(LIVE_DB_FAVORITES)
        db?.execSQL(LIVE_DB_RESERVATION)
        db?.execSQL(LIVE_DB_LIVE_VERSION)
    }

    /**
     * 旧版sdk.jar中针对 oldVersion==11&&newVersion==12和newVersion==18做其他表单独处理
     * 新版中只针对频道收藏和节目单预约功能做表创建，区别旧版点
     */
    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        Log.v(TAG, "--DatabaseHelper--onUpgrade--oldVersion:$oldVersion; newVersion:$newVersion")
        db?.execSQL("DROP TABLE IF EXISTS $FAVORITES_DB_TABLE")
        db?.execSQL("DROP TABLE IF EXISTS $RESERVATION_DB_TABLE")
        db?.execSQL("DROP TABLE IF EXISTS $VERSION_DB_TABLE")
        onCreate(db)
    }

}